package com.ruoyi.web.controller.construction;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.violation.vo.LawAuditVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.construction.domain.ConstructionSite;
import com.ruoyi.construction.service.IConstructionSiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目工地信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/construction/site")
public class ConstructionSiteController extends BaseController
{
    @Autowired
    private IConstructionSiteService constructionSiteService;

    /**
     * 分页查询项目工地信息列表
     */
    @PreAuthorize("@ss.hasPermi('construction:site:query')")
    @GetMapping("/page")
    public TableDataInfo page(ConstructionSite constructionSite)
    {
        startPage();
        List<ConstructionSite> list = constructionSiteService.selectConstructionSiteList(constructionSite);
        return getDataTable(list);
    }
    /**
     * 查询项目工地信息列表
     */
    @PreAuthorize("@ss.hasPermi('construction:site:query')")
    @GetMapping("/list")
    public AjaxResult list(ConstructionSite constructionSite)
    {
        List<ConstructionSite> list = constructionSiteService.selectConstructionSiteList(constructionSite);
        return AjaxResult.success(list);
    }

    /**
     * 导出项目工地信息列表
     */
    @PreAuthorize("@ss.hasPermi('construction:site:export')")
    @Log(title = "项目工地信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConstructionSite constructionSite)
    {
        List<ConstructionSite> list = constructionSiteService.selectConstructionSiteList(constructionSite);
        ExcelUtil<ConstructionSite> util = new ExcelUtil<ConstructionSite>(ConstructionSite.class);
        util.exportExcel(response, list, "项目工地信息数据");
    }

    /**
     * 获取项目工地信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('construction:site:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(constructionSiteService.selectConstructionSiteById(id));
    }

    /**
     * 新增项目工地信息
     */
    @PreAuthorize("@ss.hasPermi('construction:site:add')")
    @Log(title = "项目工地信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionSite constructionSite)
    {
        return toAjax(constructionSiteService.insertConstructionSite(constructionSite));
    }

    /**
     * 修改项目工地信息
     */
    @PreAuthorize("@ss.hasPermi('construction:site:edit')")
    @Log(title = "项目工地信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionSite constructionSite)
    {
        return toAjax(constructionSiteService.updateConstructionSite(constructionSite));
    }

    /**
     * 删除项目工地信息
     */
    @PreAuthorize("@ss.hasPermi('construction:site:remove')")
    @Log(title = "项目工地信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(constructionSiteService.deleteConstructionSiteByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('violation:project:remove')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody LawAuditVo lawAuditVo){
        lawAuditVo.setAuditUserId(getUserId());
        lawAuditVo.setAuditUserName(getUsername());
        return toAjax(constructionSiteService.audit(lawAuditVo));
    }
}
